#!/usr/bin/env python
# -*- coding: utf-8 -*-

# thirdpart modules
import cx_Oracle

class ConnectionMgr():
    def __init__(self, connstr=None):
        self._conn = None
        self.connect(connstr)

    def connect(self, connstr):
        if self._conn:
            self.close()
        if connstr:
            self._conn = cx_Oracle.connect(connstr)

    def conn(self):
        return self._conn

    def close(self):
        self._conn.close()
        self._conn = None

if __name__ == '__main__':
    mgr = ConnectionMgr('mig_tool/smart@orcl')
    print 'mgr =', mgr
    print mgr.conn
    mgr.close()
